package edu.spbu.eclipse.addressbook.andrpodk;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.part.EditorActionBarContributor;

public class AddressBookActionBarContributor extends EditorActionBarContributor{
	private AddressBookEditor activeEditor;
	private Action newEntryAction;
	private Action changeEntryAction;
	private Action deleteEntryAction;
	private Action findAction;
	private Action findNextAction;

	public AddressBookActionBarContributor(){
		newEntryAction=new Action("New Entry"){
			public void run(){
				activeEditor.performNewEntryAction();				
			}			
		};
		changeEntryAction=new Action("Change Entry"){
			public void run(){
				activeEditor.performChangeEntryAction();
			}
		};
		deleteEntryAction=new Action("Delete Entry"){
			public void run(){
				activeEditor.performDeleteEntryAction();
			}
		};
		findAction=new Action("Find"){
			public void run(){
				activeEditor.performFindAction();
			}
		};
		findNextAction=new Action("Find Next"){
			public void run(){
				activeEditor.performFindNextAction();
			}
		};				
	}
	public void contributeToMenu(IMenuManager menuManager){
		super.contributeToMenu(menuManager);
		MenuManager addressBookMenu = new MenuManager("AddressBook");
		menuManager.insertAfter("additions", addressBookMenu);
		addressBookMenu.add(newEntryAction);
		addressBookMenu.add(changeEntryAction);
		addressBookMenu.add(deleteEntryAction);
		addressBookMenu.add(new Separator());
		addressBookMenu.add(findAction);
		addressBookMenu.add(findNextAction);
	}
	public void setActiveEditor(IEditorPart part){
		activeEditor=(AddressBookEditor)part;				
	}	
}
